﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HaierCADplug_in
{
    public class ConfigManager
    {
        private string _filePath;

        public ConfigManager(string filePath)
        {
            _filePath = filePath;

        }

        public XElement LoadSettings()
        {
            if (File.Exists(_filePath))
            {
                return XElement.Load(_filePath);
            }
            else
            {
                // 创建默认配置
                //CreateDefaultSettings();
                throw new FileNotFoundException("");
            }
        }

        public void SaveSettings(XElement settings)
        {
            settings.Save(_filePath);
        }
       

        private void CreateDefaultSettings()
        {
            XElement defaultSettings = new XElement("Settings",
                new XElement("Personal",
                    new XElement("Username", "defaultUser"),
                    new XElement("Email", "email@example.com")),
                new XElement("Preferences",
                    new XElement("Theme", "Light"),
                    new XElement("FontSize", "14")),
                new XElement("Advanced",
                    new XElement("NetworkConfiguration", "192.168.1.1"),
                    new XElement("LoggingEnabled", "false"))
            );
            defaultSettings.Save(_filePath);
        }

    }
}
